package com.example.q_kang.hhh.setting;


import com.example.q_kang.hhh.R;
import com.example.q_kang.hhh.home.InviteFriendFragment;
import com.example.q_kang.hhh.home.TeamManagerFragment;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.sskj.base.MVPActivity;
import com.example.q_kang.hhh.setting.OrderPeizhiPresenter;
import com.sskj.base.adapter.MyFragmentPagerAdapter;
import com.sskj.base.base.App;
import com.sskj.base.data.TabEntity;
import com.sskj.base.view.ToolBarLayout;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/04/18
 */
public class OrderPeizhiActivity extends MVPActivity<OrderPeizhiPresenter> {
    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.commonTabLayout)
    CommonTabLayout commonTabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private String[] mTitles = {App.INSTANCE.getString(R.string.zhudan_peizhi), App.INSTANCE.getString(R.string.fulidan_peizhi)};
    private ArrayList<Fragment> mFragments;

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_peizhi;
    }

    @Override
    public OrderPeizhiPresenter getPresenter() {
        return new OrderPeizhiPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());
        mFragments = new ArrayList<>();
        mFragments.add(SingleFragment.newInstance());
        mFragments.add(WelfareFragment.newInstance());

        ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i]));
        }
        commonTabLayout.setTabData(mTabEntities);

        commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position, true);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragments));

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                commonTabLayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, OrderPeizhiActivity.class);
        context.startActivity(intent);
    }

}
